class Student{
    private   String name;//此时name只能在student类中使用
    private  int age;
    private String sex;//默认权限
    public static int  classroom=112;//如果一个成员变量被static修饰后就不属于这个对象
    //存储在方法区
    //生命周期伴随类的一生



    public String getMane() {
        return name;
    }

    public void setMane(String mane) {
        this.name = mane;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }



    public Student(){
        System.out.println("没有参数的构造方法");
    }

//    public Student(String name, int age, String sex, int classroom) {
//        this.name = name;
//        this.age = age;
//        this.sex = sex;
//        this.classroom = classroom;
//    }

    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
    {
        System.out.println("构造代码块/实例代码块/非静态代码块");
        this.name="zhangsan";
        //实例化代码块的执行优先于构造代码块
        //实例代码块和实例成员变量的执行分前后顺序，
    }
    static {
        System.out.println("静态代码块");
        classroom=113;
        //静态代码块优先被执行，其次是实例代码块，构造代码块

    }

    public void eat(){

        System.out.println(this.name +" is eating");
    }
    public void sleep(){
        System.out.println(this.name+" is sleeping");
    }
    public  void show(){
        System.out.println("姓名"+this.name+"年龄"+this.age+"性别"+this.sex);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }

    public static int classname(){
        Student student=new Student();
        student.eat();//若想在静态方法中调用非静态的可以重新实体化一个对象
        return classroom;
    }
}


public class Test {
    public static void main(String[] args) {
        Student student1=new Student("zhangsan",10,"nan");
        System.out.println(student1);//地址
       // student1.show();

    }
    public static void main4(String[] args) {
        Student student=new Student();
        Student student1=new Student();
        //静态代码块只执行一回（类只会被加载一回）

    }
    public static void main3(String[] args) {
        {
            //定义在方法里面的，称为普通代码块
        }
    }
    public static void main2(String[] args) {//这里也是静态方法，所以需要实体化对象，不能直接调用非静态变量
        Student student1=new Student("zhangsan",10,"nan");
        Student student2=new Student("lisi",11,"nv");
        Student student3=new Student("wangwu",8,"nan");
        Student student4=new Student("lili",9,"nan");
        System.out.println(Student.classroom);//通过类名去访问
        //静态成员变量不依赖于对象
        int ret=Student.classname();
        System.out.println(ret);
        //静态方法不需要对象的调用，所以当在静态方法中调用需要对象的是不可以的
    }







    public static void main1(String[] args) {
        Student student1 = new Student();
        student1.setMane("wangwu") ;
        System.out.println(student1.getMane());
        student1.eat() ;

    }

}
